package server;

import java.io.Serializable;
import java.util.ArrayList;
import domain.Bill;

public class Bills implements Serializable {

	private ArrayList<Bill> bills;
	private static Bills instance;
	private static final Object singletonObject = new Object();

	private Bills(){
		this.bills = new ArrayList<Bill>();
	}

	public static Bills getInstance() {
		if(instance==null) {
			synchronized(singletonObject) {
				if(instance == null) {
					instance = new Bills();
				}
			}
		}
		return instance;
	}

	public void add(Bill bill){
		synchronized(this) {
			bills.add(bill);
		}
	}

	public void remove(Bill bill){
		synchronized(this) {
			bills.remove(bill);
		}
	}

	public Bill getBill(String user) {
		Bill result = null;
		synchronized(this) {
			for(Bill b : bills) {
				if(user.equals(b.getUser())) {
					result = b;
				}
			}
		}
		
		return result;
	}

}
